package com.scoy.honeymei.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.scoy.honeymei.R;
import com.scoy.honeymei.bean.MallOrderBean;
import com.scoy.honeymei.utils.GlideImgUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @ClassName: NormalAdapter$
 * @Description:
 * @Author: GaoZhan
 * @CreateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/8/26/0026$ 下午 17:03$
 * @UpdateRemark: 更新内容
 */
public class OrderImgAdapter extends RecyclerView.Adapter {
    private Context context;
    private ArrayList<MallOrderBean.GoodsListBean> datalist;


    public OrderImgAdapter(Context context, ArrayList<MallOrderBean.GoodsListBean> datalist) {
        this.context = context;
        this.datalist = datalist;

    }

    public interface OnOneClick {
        void oneClick(int pos);
    }

    OnOneClick onOneClick;

    public void setOnOneClick(OnOneClick onOneClick) {
        this.onOneClick = onOneClick;
    }

    public interface OnTwoClick {
        void twoClick(int pos);
    }

    OnTwoClick onTwoClick;

    public void setOnTwoClick(OnTwoClick onTwoClick) {
        this.onTwoClick = onTwoClick;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_img0, parent, false);
        return new ImgHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ImgHolder imgHolder = (ImgHolder) holder;
        MallOrderBean.GoodsListBean goodsListBean = datalist.get(position);
        GlideImgUtil.glidePic(context, goodsListBean.getImage(), imgHolder.imgIv);

        imgHolder.imgIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onOneClick!=null){
                    onOneClick.oneClick(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return datalist == null ? 0 : datalist.size();
    }

    class ImgHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_iv)
        ImageView imgIv;

        ImgHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
